package eliauk.fun.flowabledemo.config;

import eliauk.fun.flowabledemo.listener.GlobalProcessInstanceListener;
import eliauk.fun.flowabledemo.mapper.CustomCommentMapper;
import org.flowable.common.engine.api.delegate.event.FlowableEventListener;
import org.flowable.engine.RuntimeService;
import org.flowable.spring.SpringProcessEngineConfiguration;
import org.flowable.spring.boot.EngineConfigurationConfigurer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashSet;
import java.util.Set;

@Configuration
public class FlowableConfig implements EngineConfigurationConfigurer<SpringProcessEngineConfiguration>, CommandLineRunner {

    @Override
    public void configure(SpringProcessEngineConfiguration engineConfiguration) {
        engineConfiguration.setActivityFontName("宋体");
        engineConfiguration.setLabelFontName("宋体");
        engineConfiguration.setAnnotationFontName("宋体");


        //自定义sql
        Set<Class<?>> customMybatisMappers = new HashSet<>();
        customMybatisMappers.add(CustomCommentMapper.class);
        engineConfiguration.setCustomMybatisMappers(customMybatisMappers);
    }

    @Autowired
    private GlobalProcessInstanceListener globalProcessInstanceListener;

    @Autowired
    private RuntimeService runtimeService;

    @Override
    public void run(String... args) throws Exception {
        runtimeService.addEventListener(globalProcessInstanceListener);
    }
}